const { SDK, baseURL } = require('./config')
const OpenAI = require('openai').default

class AiTalk {
  constructor() {
    this.initDP()
  }
  initDP() {
    if (AiTalk.instance) {
      return AiTalk.instance
    }

    this.openai = new OpenAI({
      baseURL,
      apiKey: SDK
    })
  }
  async dpChat(content) {
    try {
      const result = await this.openai.chat.completions.create({
        messages: [{ role: 'user', content }],
        model: 'deepseek-chat',
        // 采用流式传输
        stream: true
      })
      if (result) {
        // 得到的结果直接返回
        return result
      }
    } catch (error) {
      console.log(error)
    }
  }
}

module.exports = new AiTalk()
